package com.sdry.service.impl.llm;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.sdry.mapper.llm.ExceptionLogMapper;
import com.sdry.model.llm.ExceptionLog;
import com.sdry.service.llm.ExceptionLogService;

/** 
* @author lian 
* @version 1.0
* @time 2018年10月17日 上午12:55:08
*/

@Service
public class ExceptionLogServiceImp implements ExceptionLogService{

	@Resource
	private ExceptionLogMapper exceptionLogMapper;
	
	/**
	 * 把异常信息写入表中
	 * @param log
	 */
	@Override
	public int insertExceptionLogSelective(ExceptionLog log) {
		return exceptionLogMapper.insertExceptionLogSelective(log);
	}

	/**
	 * 查日志总数
	 * @param exceptionLog
	 */
	@Override
	public int countExceptionLog(ExceptionLog exceptionLog) {
		return exceptionLogMapper.countExceptionLog(exceptionLog);
	}

	/**
	 * 分页查询异常日志信息
	 * @param map
	 */
	@Override
	public List<ExceptionLog> listPageExceptionLog(Map<String, Object> map) {
		return exceptionLogMapper.listPageExceptionLog(map);
	}

	/**
	 * 删除异常日志
	 * @param str 异常表的id组成的字符串
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public int deleteExceptionLog(String str) {
		int isSuccess = 0;
		String[] split = str.split(",");
		try {
			for (String lid : split) {
				isSuccess = exceptionLogMapper.deleteExceptionLog(Long.parseLong(lid));
			}
		}catch (
		Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		return isSuccess;
	}

}
